package com.xmy.count;

import java.util.concurrent.CountDownLatch;

//计数器
public class CountDownLatchDemo {
    public static void main(String[] args) throws InterruptedException {
        //总计数为6
        CountDownLatch countDownLatch = new CountDownLatch(6);

        for (int i = 0; i < 6; i++) {
            new Thread(()->{
                System.out.println(Thread.currentThread().getName()+"Go out");
                countDownLatch.countDown();// 计数-1
            },String.valueOf(i)).start();
        }

        countDownLatch.await(); //阻塞线程，等待计数器归零，然后再向下执行。

        System.out.println("Close Door!");


    }
}
